<?php include("session.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Sản phẩm</title>
<?php 
    include_once("import.php");
    include("./service/productService.php");
?>
</head>

<body>
<!-- Wrapper -->
<div class="wrapper">
	<!-- Floating banner -->
    <?php include("floating-banner.php");?>
    <!-- End of floating banner -->

	<!-- Top banner -->
	<?php include("header.php");?>
    <!-- End of top banner -->
    
    <!-- Navigator -->
	<?php include("navigator.php");?>
    <!-- End of navigator -->
    
    <!-- Menu, newsletter and search -->
    <?php include("menu.php");?>
    <!-- End of menu, newsletter and search -->
    
    <!-- Content -->
    <div class="wrapper-content">
    	
        <!-- Breadcrumb -->
        <?php include("breadcrumb.php");?>
        <!-- End of breadcrumb -->
        
        <!-- Index product wrapper -->
   		<div class="index-product-wrapper">
        </div>
        <!-- End of index product wrapper -->
		
        <div class="clear"></div>
		
        <!-- Paging -->
        <div class="index-paging-wrapper">
        	<?php
                $products = getProductOfCategory(isset($_GET["c"])?$_GET["c"]:0,null,null);
                $numbOfProduct = mysql_num_rows($products);
                if($numbOfProduct>0){
            ?>
                <div id="example_paging" class="paging"></div>
                <script type='text/javascript'>
                    var options = {
                        alignment:"right",
                        currentPage: 1,
                        totalPages: <?php echo ceil($numbOfProduct / 8); ?>,
                        onPageClicked: function(e,originalEvent,type,page){
                            $.ajax({
                                type: "GET",
                                url: "./action/ajax/getProduct.php",
                                data: { p: page,c: <?php echo isset($_GET["c"])?$_GET["c"]:0; ?>}
                            }).done(function( data ) {
                                $(".index-product-wrapper").empty();
                                $(".index-product-wrapper").html(data);
                                c =  <?php echo isset($_GET["c"])?$_GET["c"]:0; ?>;
                                p=page;
                            });
                        }
                    }
            
                    $('#example_paging').bootstrapPaginator(options);
                </script>
            <?php
                }
            ?>
        </div>
        <!-- End of Paging -->
    </div>
    <!-- End of content -->
	
    <!-- Live support -->
        <?php include("live-support.php");?>
    <!-- End of live support -->
    
	<?php include("footer.php");?>
</div>
<!-- End of wrapper -->
<script>
    $(document).ready(function(){
        $.ajax({
            type: "GET",
            url: "./action/ajax/getProduct.php",
            data: { p: 1,c:<?php echo isset($_GET["c"])?$_GET["c"]:0; ?>,user:userid }
        }).done(function( data ) {
            $(".index-product-wrapper").html(data);
            $(".product-price").each(function(){
                var price = $(this).html();
                $(this).html(formatCurrency(price,2));
                c =  <?php echo isset($_GET["c"])?$_GET["c"]:0; ?>;
                p=1;
            });
        });
    });
	
	function addToCart(proId){
		$.ajax({
			type: "POST",
			url: "action/ajax/addProductToCartProcess.php",
			data: { "proId" : proId, "quantity" : 1},
			success: function(data){
				$("#numPro").html("(" + data + ")");
			}
		});
	}
    
    $(document).ready(function(){
        $.ajax({
			type: "POST",
			url: "action/ajax/generateBreadcrumb.php",
			data: { "c" : <?php echo isset($_GET["c"])?$_GET["c"]:0; ?>},
			success: function(data){
				$(".breadcrumb-wrapper").html(data);
			}
		});        
    });

</script>
</body>
</html>
